package com.base.myproject.client.busi;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.SendServlet;
import com.base.myproject.client.tools.XML;
import com.base.myproject.client.ui.BaseBusiLeftPanel;
import com.base.myproject.client.ui.BaseCopyUI;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseImageList;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.FormImage;
import com.base.myproject.client.ui.celleditor.BaseCellEditorCB;
import com.base.myproject.client.ui.celleditor.BaseComboBox;
import com.base.myproject.client.ui.celleditor.BaseGridEditor;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid.ClicksToEdit;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.menu.Item;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormHandler;
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormSubmitEvent;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

public class CodeBusi extends BaseJDBCPanel{
	private FormBinding formBindings;
	FormBinding formBindings2;
	static BaseStore<JDBCModelData> store = null;
	static BaseStore<JDBCModelData> codelinkstore = null;
	static BaseStore<JDBCModelData> codeimagestore = null;
	static BaseGrid grid2 = null;
	static BaseGrid grid = null;
	static ListView view = null;
	 static BaseComboBox combo=null;
	static  BaseStore<JDBCModelData>    customertypestore = null ;
	static BaseStore<JDBCModelData>  branchorgadd  = null;
	static  BaseStore<JDBCModelData>  officestore = null;
	public CodeBusi()
	{
		super();
		init();
	}
	public void init(){
		
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
	this.add(initWeiget(),centerData);
		
	}
	 @SuppressWarnings("unchecked")
	public ContentPanel initWeiget() {  
		    setLayout(new FlowLayout(10)); 

		    RowNumberer r = new RowNumberer();  
		    //--set columns
		    CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
			   
		   // cbs.setSelectionMode(Style.SelectionMode.SINGLE);
		    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		   // columns.add(r);
		   // columns.add(cbs.getColumn());
		    ColumnConfig column = new ColumnConfig("ccode", "ccode", 100); 
		    TextField<String> text = new TextField<String>(); 
		    column.setEditor(new CellEditor(text));
//		    column.setRenderer(renderer)
		    columns.add(column);
		    
		    
		    ModelType combotype = new ModelType();  
		    combotype.setRoot("records") ;  
		    combotype.setRecordName("record");  
		    combotype.setTotalName("totle");
		    combotype.addField("code","ccode");  
		    combotype.addField("name","cname");  
		    StoreInfo  comboinfo= new StoreInfo();
		    
		    comboinfo.setTablename("ccode");
		    comboinfo.setSql("select ccode,cname from ccode");
		 
	    final BaseComboBox<ModelData> combo2=new BaseComboBox<ModelData>(combotype,comboinfo);  
		    combo2.setLazyRender(false);
		    
		   final BaseModel m1 = new BaseModel(); 
		    m1.set("name", "zgw1");
		    m1.set("value", "zgwvalue1");
		  // combo2.doQuery("q", false);
		    BaseCellEditorCB  editor = new BaseCellEditorCB(combo2,"code","name");
		  
//			    CellEditor editor = new CellEditor(combo2) {  
//			        @Override  
//			        public Object preProcessValue(Object value) {  
//			        	  System.out.println("preprocessvalue="+value);
//			          if (value == null) {  
//			            return value;  
//			          }  
//			       //  return m3;
//			          System.out.println(combo2.getValue() == null);
//			          return combo2.getValue();  
//			         // return null;
//			        }  
//			    
//			        @Override  
//			        public Object postProcessValue(Object value) {  
//			          if (value == null) { 
//			        	 // return m1;
//			        	  System.out.println(" value is null");
//			        	//s return m1.get("name");
//			            return value;  
//			          }  
//			        //  return ((ModelData) value).get("name");
//			          
//			          System.out.println(" value is not null");
//			          return combo2.getValue().get("name");
//			
//			        }  
//			      };  
//			   
		  ColumnConfig cname = new ColumnConfig("cname", "cname", 100); 
		    TextField<String> gnametext = new TextField<String>(); 
		   // gname.setEditor(new CellEditor(gnametext));
		   // cname.setEditor(new CellEditor(combo2));
		    cname.setEditor(editor);
		    columns.add(cname);
		    DateField dateField = new DateField();  
		  //  columns.add(new ColumnConfig("Phone", "Phone", 100)); 
		   // columns.add(new ColumnConfig("imageurl", "图片", 100));  
		    ColumnModel cm = new ColumnModel(columns);  
		    
		    //--set modetype 
		    ModelType type = new ModelType();  
		    type.setRoot("records") ;  
		    type.setRecordName("record");  
		    type.setTotalName("totle");
		    type.addField("ccode");  
		    type.addField("cname");  
//		    type.addField("Phone");  
//		    type.addField("imagepath");  
		    StoreInfo info= new StoreInfo();
		    info.setTablename("ccode");
		    info.setSql("select * from ccode");
		    
		    info.setKeyname(new String[]{"ccode"});
			
		    
		    //----
		    BaseBusiLeftPanel basbusileftpanel = new BaseBusiLeftPanel(columns,type,info);
		    store = basbusileftpanel.getStore();
		    //----
		    ContentPanel panel = new ContentPanel();  
	   store = new BaseStore<JDBCModelData>(type,info);
		    store.setName("parent");
		//    store.load();
		    
		    
		    
		    //--- 默认值
		    java.util.HashMap<String, Object> defaultvalue = new java.util.HashMap<String, Object>();
		    defaultvalue.put("ccode", "9999");
		    defaultvalue.put("cname", "zgwzzz");
		    
		    store.setDefaultvalue(defaultvalue);
		    
		    //---
		   grid=new BaseGrid(store, cm);
		    
		   grid.setSelectionModel(cbs);
		    grid.setBorders(true);  
		    grid.setAutoExpandColumn("ccode");  
		  ContentPanel panel2 =uploadpanel();//createImagePanel();
		    grid.addPlugin(cbs);
		    grid.addPlugin(r);  
		    grid.getView().setForceFit(true);  
		    grid.setClicksToEdit(ClicksToEdit.TWO);
		    
//		    Menu m = new Menu();
//		    Item item = new MenuItem( "Respond", "reply-menu-item", new SelectionListener<MenuEvent>() {
//
//		    @Override
//		    public void componentSelected(MenuEvent ce) {
////		    int rowIndex = do something here to get the row index
////		    handleReplyRequest( rowIndex );
//		    }
//
//		    });
//		    m.add( item );
//		    grid.setContextMenu(m);
		    grid.setStripeRows(true);
		    grid.setTrackMouseOver(true);
	
		    grid.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent>() {  
		        public void handleEvent(SelectionChangedEvent be) {  
		          if (be.getSelection().size() > 0) {  
		        	  
		            formBindings.bind((ModelData) be.getSelection().get(0)); 
		           

		          } else {  
		            formBindings.unbind();  
		          }  
		        }  
		      });  
		    FormPanel formpanel = createForm();  
		    formBindings = new FormBinding(formpanel, true);  
		    formBindings.setStore(grid.getStore()); 
		    
		    formBindings.addListener(Events.SelectionChange, new Listener<SelectionEvent>(){

				@Override
				public void handleEvent(SelectionEvent be) {
					// TODO Auto-generated method stub
					System.out.println("formbindings changed");
				}

				
				});
		   
		    panel.setScrollMode(Scroll.AUTO);
		    panel.setIconStyle("icon-table");  
		   //-----------------------------布局
  
		    panel.setLayout(new RowLayout(Orientation.HORIZONTAL)); 
		  
		    ContentPanel leftpanel = new ContentPanel();
		    
		    leftpanel.setLayout(new  RowLayout(Orientation.VERTICAL));
	    StoreFilterField<ModelData> field = new StoreFilterField<ModelData>() {  
		        @Override  
		        protected boolean doSelect(Store<ModelData> store, ModelData  parent, ModelData  record,  
		            String property, String filter) {  
		        	 String name = (String)record.get("cname");  
		  
		          if (name.indexOf(filter.toLowerCase()) != -1) {  
		            return true;  
		          }  
		          return false;  
		        }  
		    
		        @Override  
		        protected void onFilter() {  
		          super.onFilter();  
		        
//		          grid.getSelectionModel().select(0);  
		        }  
		    
		      };  

//		      field.bind(store);  
		      leftpanel.add(field, new RowData(1, 0.1));
		    
		    PagingToolBar toolBar = new PagingToolBar(2); 
		    toolBar.bind((BasePagingLoader)store.getLoader()); 
	 
		    
		    
		    leftpanel.add(basbusileftpanel.getPanel(), new RowData(1, 1));
		  //  leftpanel.setBottomComponent(toolBar); 
		    panel.add(leftpanel, new RowData(.2, 1));  
		    ContentPanel panelrigth2 = new ContentPanel();  
		    
		    
			  	    
		    
		    ContentPanel panelrigth = new ContentPanel();  
		    panelrigth.setHeaderVisible(false);
		   // System.out.println("panelrigth="+panelrigth);
		    ContentPanel panelrigthtop = new ContentPanel(); 
		    panelrigthtop.setHeaderVisible(false);
		    panelrigthtop.setLayout( new RowLayout(Orientation.HORIZONTAL));
		    panelrigthtop.add(formpanel,new RowData(.5, 1));
		   final BaseFormPanel basefrompanel = createCodeImagesPanel();
		    panelrigthtop.add(basefrompanel,new RowData(.5, 1));
		    panelrigth.setLayout(new BorderLayout());  
		  //  panelrigth.setLayout(new RowLayout(Orientation.VERTICAL)); 
		    
		    
		    BorderLayoutData westData = new BorderLayoutData(LayoutRegion.NORTH, 200, 100, 300);  
		    westData.setMargins(new Margins(0, 0, 0, 0));  
		    westData.setSplit(true);  
		   // container.add(west, westData);
		    
		    panelrigth.add(panelrigthtop,westData); 
		      
		    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
		    centerData.setMargins(new Margins(5)); 
		    //centerData.setSplit(true);  
		
		    panelrigth.add(panel2,centerData);  
		  
		  panel.add(panelrigth,new RowData(.8, 1));  
		  
		    //---------------------------布局结束
		    
		    panel.addButton(new Button("test",new  SelectionListener<ButtonEvent>()
		    {

				@Override
				public void componentSelected(ButtonEvent ce) {
					// TODO Auto-generated method stub
				//	BaseImageDialog bid = new BaseImageDialog();
				//	bid.show();
//					System.out.println(combo.getValueField());
//					System.out.println(combo.getData());
//					System.out.println(combo.getOriginalValue());
//					System.out.println(combo.getRawValue());
//					System.out.println(combo.getRegex());
//					System.out.println(combo.getValue().get("value"));
//					System.out.println(combo.getValue().get("name"));
					
					 el().mask("正在读取记录......");
					
					
				}
		    	
		    }));
		    panel.addButton(new Button("Commit parent", new SelectionListener<ButtonEvent>() {  
	    	       @Override  
	    	       public void componentSelected(ButtonEvent ce) {  
	    	    	  // System.out.println("beforesave="+grid.getStore().getAt(0).get("Sender"));
	    	    	//   grid.getStore().removeAll();
	    	        // grid.getStore().commitChanges(); 
	    	    	  // store.gotorow(1);
//	    	    	   StoreInfo info= new StoreInfo();
//	    			    info.setTablename("ccode");
//	    			    info.setSql("select * from ccode");
//	    			    ModelType type = new ModelType();  
//	    			    type.root = "records";  
//	    			    type.recordName = "record";  
//	    			    type.addField("ccode", "ccode");  
//	    			    type.addField("cname");  
//	    			    type.addField("Phone");  
//	    	    	   store=new BaseStore(type,info);
	    	    	  
	    	    	  //  store=new BaseStore( store.getType(), store.getStoreinfo());
	    	    	//   store.reload();
	    	    	//   grid.reconfigure(store, grid.getColumnModel());
	    	    	 //  formBindings2.bind(codeimagestore.getAt(0));
	    	    	  // basefrompanel.getBasestore().gotorow(1);
	    	    	  // grid2.getView().refresh(true);
	    	    	 //  System.out.println("ccode="+grid2.getValue("ccode"));
	    	    	   
	    	    	  System.out.println(      view.getSelectionModel().getSelectedItem().get("imagepath"));
	    	    	  view.getSelectionModel().getSelectedItem().set("imagepath", "images/test/photos/1.jpg");
	    	    	  view.refresh();
	    	    	  // try {
//	    	    	   it("Got value --" + grid2);
//	    	    	   it("Got value --" + grid2.getValue("ccode"));
//	    	    	   it("Got value --" + grid2.getStore().getAt(0).getProperties().get("ccode"));
//	    	    	   it("Got value --" + grid2.getStore().getCount());
//	    	    	   it("Got value --" + grid2.isVisible());
//	    	    	   it("Got value --" + grid2.getView().toString());
//	    	    	   grid2.getView().refresh(true);
	    	    		 //  GWT.log("Got value ++",null);
	    	    		 //  alert("");
	    	    		//   GWT.log("Got value --" + grid2.getValue("ccode"), null);
	    	    		    //  GWT.log("Got value " + myValue, null);
	    	    	//	   } catch (Exception e) {
	    	    		 //     GWT.log("JSNI method badExample() threw an exception:", e);
	    	    	//	   }
	    	    	  
	    	    	 //  codeimagestore.getAt(0);
	    	    	  // System.out.println("move...parent");
	    	 
	    	    	 //  grid.getStore().remove(grid.getSelectionModel().getSelectedItem());
	    	      //  System.out.println("aftersave="+grid.getStore().getAt(0).get("Sender"));
	    	       }  
	    	    }));  
		 //   Image jimmyFull =new Image();
		    
//		    jimmyFull.setUrl("http://www.google.cn/intl/zh-CN/images/logo_cn.gif");
//		    panel.add(jimmyFull,new RowData(.6, 1));  
		    //tab页
		    TabPanel tabpanel = new TabPanel();  
		  //  tabpanel.setPlain(true); 
		    tabpanel.setWidth(450);  
		    tabpanel.setHeight(450);  
		    tabpanel.setAutoHeight(true);  
		    TabItem normal = new TabItem("Normal");  
		    ContentPanel branchorg = new ContentPanel();//createCcodebranchorgaddPanel
		    
		    
		    branchorg.setHeight(400);
		    branchorg.setHeaderVisible(false);
		    branchorg.setLayout(new RowLayout(Orientation.VERTICAL));
		    branchorg.add(createOfficePanel(),new RowData(1, 0.5));
		   branchorg.add(createCcodebranchorgaddPanel(),new RowData(1, 0.5));
		    normal.add(branchorg);
		   //normal.add(new HTML("0000000000"));
		    TabItem normal2 = new TabItem("Normal2");  
		 //   normal2.add(new HTML("0000000000"));
		    ContentPanel normal2panel = new ContentPanel();
		    normal2panel.setLayout(new TableLayout(3));
		    TableData td1= new TableData();
		    td1.setColspan(6);
		 //   td1.setHeight("100px");
		   // td1.setWidth("100px");
		    TableData td2= new TableData();
		    td2.setColspan(4);
		   
		    TableData td3= new TableData();
		    td3.setColspan(1);
		    normal2panel.add(new HTML("ddd"),td1);
		    normal2panel.add(new HTML("ddd222"),td2);
		    normal2panel.add(new HTML("zzz"),td3);
		  
		    normal2.add(createImagePanel());
		  
		    
		   	    
		    
		    tabpanel.add(normal2);
		  
		    tabpanel.add(normal);
		   
		    TabItem normal3 = new TabItem("联系人");  
		    normal3.add(createLinkManPanel());
		    tabpanel.add(normal3);
		    
		 
		    panelrigth2.setLayout(new FitLayout());
		    BorderLayoutData centerData2 = new BorderLayoutData(LayoutRegion.CENTER);
			centerData2.setMargins(new Margins(0));
		    panelrigth2.add(tabpanel);
		  
		    panel.add(tabpanel,new RowData(.8, 1));  
		    store.setKeyname(new String[]{"ccode"});
		    setMaincomponent(grid);
			registerMainStore(store);
			this.registerStore(store);
		    return panel;
	 }
	 private FormPanel createForm() {  
		    FormPanel panel = new FormPanel();  
		    panel.setHeaderVisible(false);  
		  
		    TextField<String> name = new TextField<String>();  
		    name.setName("ccode");  
		    name.setFieldLabel("Name"); 
		    
		    panel.add(name);  
		  
		    TextField<String> symbol = new TextField<String>();  
		    symbol.setName("cname");  
		    symbol.setFieldLabel("Symbol");  
		    
		    panel.add(symbol);  
		  
		    TextField open = new TextField();  
		    open.setName("phone");  
		    open.setFieldLabel("Last");  
		    panel.add(open);  
		  
		    TextField change = new TextField();  
		    change.setName("change");  
		    change.setFieldLabel("Change");  
		    
		    panel.add(change);  
		  
		    DateField last = new DateField();  
		    last.setName("date");  
		    last.setFieldLabel("Updated");  
		    panel.add(last);  
		    
		    FormImage lf = new FormImage();
		    lf.setName("imageurl");
		    lf.setFieldLabel("zzdd");
		   
		    panel.add(lf);  
		   
		    panel.addListener(Events.SelectionChange, new Listener(){

				@Override
				public void handleEvent(BaseEvent be) {
					// TODO Auto-generated method stub
					System.out.println("formpanel selectionchanged!!!!");
				}
		    	
		    });
		  //  com.extjs.gxt.ui.client.widget.form.
		    panel.setHeaderVisible(false);
		    return panel;  
		  }  
	 
	 public BaseFormPanel createCodeImagesPanel() {  
		
		    TextField<String> name = new TextField<String>();  
		    name.setName("ccode");  
		    name.setFieldLabel("Name"); 
		    
		    
		  
		    FormImage lf = new FormImage();
		    lf.setName("imagepath");
		    lf.setFieldLabel("imagepath");
		  
		 
//		 List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
//		 
//		    ColumnConfig column = new ColumnConfig("ccode", "ccode", 100); 
//		    ColumnConfig gname = new ColumnConfig("imagepath", "imagepath", 100); 
//		    columns.add(column);
//		    columns.add(gname);
		    
		    ModelType type = new ModelType();  
		    type.setRoot("records") ;  
		    type.setRecordName("record");  

		    type.addField("ccode", "ccode");  
		    type.addField("imagepath");  
		    
		    StoreInfo info= new StoreInfo();
		    info.setTablename("ccodeimages");
		    info.setSql("select * from ccodeimages");
		    
		    codeimagestore = new BaseStore<JDBCModelData>(type,info);
		    codeimagestore.setName("ccodeimages");
		    
		    
		    codeimagestore.setKeyname(new String[]{"ccode"});
		       codeimagestore.setParent(store);
		    codeimagestore.setLinkparentcolumns(new String[]{"ccode"});
		    //formBindings.bind(codeimagestore.getAt(0));
		    BaseFormPanel panel = new BaseFormPanel(codeimagestore); 
			 panel.setHeaderVisible(false);
			 panel.add(name);
			 panel.add(lf);  
			 panel.setHeaderVisible(false);
//			    formBindings2 = new FormBinding(panel, true);  
//			    formBindings2.setStore(codeimagestore);  
			 panel.inited();
		 return panel;
	 }
	 
	 public ContentPanel createImagePanel() {  
		 ContentPanel panel = new ContentPanel();  
		
		  ModelType type = new ModelType();  
		  type.setRoot("records") ;  
		    type.setRecordName("record");  

		    type.addField("ccode", "ccode");  
		    type.addField("imagepath");  
		    
		    StoreInfo info= new StoreInfo();
		    info.setTablename("ccodeimages");
		    info.setSql("select * from ccodeimages");
		    
		   final BaseStore<BaseModelData> imagestore = new BaseStore<BaseModelData>(type,info);
		    imagestore.setName("ccodeimages");
		    imagestore.setParent(store);
		    imagestore.setKeyname(new String[]{"ccode","idx"});
		    imagestore.setLinkparentcolumns(new String[]{"ccode"});
		    
		    BaseImageList bil = new BaseImageList(imagestore,null);
		    panel.setHeaderVisible(false);
		 /*   view = new ListView();
		    view.setAutoHeight(true);  
		    view.setTemplate(getTemplate());  
		   view.setStore(imagestore);  
		    view.setItemSelector("div.thumb-wrap");  
		    KeyNav kn = new KeyNav(view)
		    {
		    	public void onKeyPress(ComponentEvent ce) {
		    		 if(ce.isControlKey() && ce.getKeyCode()==68) 
		    		 {
		    			System.out.println( view.getSelectionModel().getSelectedItem());
		    			imagestore.remove(view.getSelectionModel().getSelectedItem());
		    		 }
		    	}
		    };
		    panel.setWidth(500);  
		   panel.add(view);  
		   panel.setHeaderVisible(false);
		   ToolBar toolBar = new ToolBar(); 
		   toolBar.setHeight("10%");
		   Button b = new Button("上传图片");
		   toolBar.add(b);
		   b.addSelectionListener(new SelectionListener<ButtonEvent>() 
		   {

			@Override
			public void componentSelected(ButtonEvent ce) {
				BaseImageDialog bid = new BaseImageDialog(imagestore);
				bid.show();
			}
			   
		   });
		   //BaseImageDialog
//		   panel.addButton(b);
		   panel.setTopComponent(toolBar);*/
		   panel.add(bil);
		 return panel;
	 }
	 //办公地址信息
	 public ContentPanel createOfficePanel() {  
		 ContentPanel panel = new ContentPanel();  
		 panel.setSize(400, 400);
		 CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		 List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		 columns.add(cbs.getColumn());
		  ColumnConfig ccode = new ColumnConfig("ccode", "ccode", 100); 
		 // columns.add(ccode);
		  
		    ColumnConfig column = new ColumnConfig("addrtype", "地址类型", 100); 
		    TextField<String> text = new TextField<String>(); 
		    column.setEditor(new CellEditor(text));
		    columns.add(column);
		    ColumnConfig addr = new ColumnConfig("addr", "街道", 100); 
		    TextField<String> addrtext = new TextField<String>(); 
		    addr.setEditor(new CellEditor(addrtext));
		    columns.add(addr);
	
		    ColumnConfig ncode = new ColumnConfig("ncode", "国别地区", 100); 
		    TextField<String> ncodetext = new TextField<String>(); 
		    ncode.setEditor(new CellEditor(ncodetext));
		    columns.add(ncode);
		    
		    
		    ColumnConfig fax = new ColumnConfig("fax", "传真", 100); 
		    TextField<String> faxtext = new TextField<String>(); 
		    fax.setEditor(new CellEditor(faxtext));
		    columns.add(fax);
		    
		   
		    
		    ColumnModel cm = new ColumnModel(columns);  
		    
		 
		 
		 ModelType type = new ModelType();  
		 type.setRoot("records") ;  
		    type.setRecordName("record");  
		
		    type.addField("ccode", "ccode");  
		    type.addField("idx");  
		    type.addField("addrtype");  
		    type.addField("addr");  
		    type.addField("ncode");  
		    type.addField("fax");  
		    StoreInfo info= new StoreInfo();
		    
		    info.setTablename("ccodeofficeaddress");
		    info.setSql("select * from ccodeofficeaddress");
		    info.setParent(store);
		    info.setAutoinccolumn("idx");
		    info.setLinkparentcolumns(new String[]{"ccode"});
		    info.setKeyname(new String[]{"ccode","idx"});
			
		    officestore = new BaseStore<JDBCModelData>(type,info);
		    officestore.setName("ccodeofficeaddress");
		    BaseGrid officegrid=new BaseGrid(officestore, cm);
			cbs.setSelectionMode(SelectionMode.SINGLE);
			officegrid.setSelectionModel(cbs);
		 //   officegrid.setAutoExpandColumn("ccode");  
		  //  panel.setLayout(new BorderLayout());
		    panel.setLayout(new FitLayout());
		    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
			centerData.setMargins(new Margins(0));
		    panel.add(officegrid);
		    //officegrid.set
		 return panel;
	 }
	 //分支机构
	 public ContentPanel createCcodebranchorgaddPanel() {  
		 ContentPanel panel = new ContentPanel();  
		 panel.setSize(400, 400);
		 List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		 
		 // ColumnConfig ccode = new ColumnConfig("ccode", "ccode", 100); 
		 // columns.add(ccode);
		  
		    ColumnConfig column = new ColumnConfig("orgname", "分支机构名称", 100); 
		    TextField<String> text = new TextField<String>(); 
		    column.setEditor(new CellEditor(text));
		    columns.add(column);
		    ColumnConfig gname = new ColumnConfig("addr", "街道", 100); 
		    TextField<String> gnametext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(gnametext));
		    columns.add(gname);
	
		    ColumnConfig ncode = new ColumnConfig("ncode", "国别地区", 100); 
		    TextField<String> ncodetext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(ncodetext));
		    columns.add(ncode);
		    
		    
		    ColumnConfig fax = new ColumnConfig("fax", "传真", 100); 
		    TextField<String> faxtext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(faxtext));
		    columns.add(fax);
		    ColumnConfig telephone = new ColumnConfig("telephone", "电话", 100); 
		    TextField<String> telephonetext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(telephonetext));
		    columns.add(telephone);
		    ColumnConfig mobil = new ColumnConfig("mobil", "电话", 100); 
		    TextField<String> mobiltext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(mobiltext));
		    columns.add(mobil);
		    ColumnConfig postcode = new ColumnConfig("postcode", "邮编", 100); 
		    TextField<String> postcodetext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(postcodetext));
		    columns.add(postcode);
		    ColumnModel cm = new ColumnModel(columns);  
		    
		 
		 
		 ModelType type = new ModelType();  
		 type.setRoot("records") ;  
		    type.setRecordName("record");  
		    type.setTotalName("totle");
		    type.addField("ccode", "ccode");  
		    type.addField("addrtype");  
		    type.addField("addr");  
		    type.addField("ncode");  
		    type.addField("fax");  
		    type.addField("telephone");  
		    type.addField("mobil");  
		    type.addField("postcode");  
		    StoreInfo info= new StoreInfo();
		    
		    info.setTablename("ccodebranchorgadd");
		    info.setSql("select * from ccodebranchorgadd");
		    info.setParent(store);
		    info.setKeyname(new String[]{"ccode"});
			
		    info.setLinkparentcolumns(new String[]{"ccode"});
		   branchorgadd = new BaseStore<JDBCModelData>(type,info);
		    branchorgadd.setName("ccodebranchorgadd");
		    BaseGrid branchorgaddstore=new BaseGrid(branchorgadd, cm);
		 //   officegrid.setAutoExpandColumn("ccode");  
		  //  panel.setLayout(new BorderLayout());
		    panel.setLayout(new FitLayout());
		    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
			centerData.setMargins(new Margins(0));
		    panel.add(branchorgaddstore);
		 return panel;
	 }
	 /**
	  * 联系人
	  * @return
	  */
	 public ContentPanel createLinkManPanel() {  
		   CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
			   
		 //  cbs.setSelectionMode(SelectionMode.SINGLE);
		   List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		    columns.add(cbs.getColumn());
		 // ColumnConfig ccode = new ColumnConfig("ccode", "ccode", 100); 
		 // columns.add(ccode);
		  
		     ColumnConfig lname = new ColumnConfig("lname", "姓名", 100); 
		    TextField<String> text = new TextField<String>(); 
		    lname.setEditor(new CellEditor(text));
		    columns.add(lname);
		    ColumnConfig dept = new ColumnConfig("dept", "部门", 100); 
		    TextField<String> depttext = new TextField<String>(); 
		    dept.setEditor(new CellEditor(depttext));
		    columns.add(dept);
		 
		    ColumnConfig headship = new ColumnConfig("headship", "职务", 100); 
		    TextField<String>headshiptext = new TextField<String>(); 
		    headship.setEditor(new CellEditor(headshiptext));
		    columns.add(headship);
		    
		 
		    ColumnConfig passportcode = new ColumnConfig("passportcode", "护照号", 100); 
		    TextField<String> passportcodetext = new TextField<String>(); 
		    passportcode.setEditor(new CellEditor(passportcodetext));
		    columns.add(passportcode);
		   
		    
			 
		    ColumnConfig postcode1 = new ColumnConfig("postcode", "邮编", 100); 
		    TextField<String> postcodetext = new TextField<String>(); 
		    postcode1.setEditor(new CellEditor(postcodetext));
		    columns.add(postcode1);
		    ColumnModel cm = new ColumnModel(columns);  
		   
		 

		 ModelType type = new ModelType();  
		 type.setRoot("records") ;  
		    type.setRecordName("record");  
		    type.setTotalName("totle");
		    type.addField("ccode", "ccode");  
		    type.addField("dept");  
		    type.addField("addr");  
		    type.addField("headship");  
		    type.addField("passportcode");  
		    type.addField("telephone"); 
		    type.addField("mobil"); 
		    StoreInfo info= new StoreInfo();
		    
		    info.setTablename("ccodelinkman_info");
		    info.setSql("select * from ccodelinkman_info");
		    info.setParent(store);
		    info.setKeyname(new String[]{"ccode"});
			
		    info.setLinkparentcolumns(new String[]{"ccode"});
		    BaseStore<JDBCModelData>  branchorgadd = new BaseStore<JDBCModelData>(type,info);
		    branchorgadd.setName("ccodelinkman_info");
			    BaseGrid branchorgaddgrid=new BaseGrid(branchorgadd, cm);
		
		    branchorgaddgrid.setSelectionModel(cbs);
		    //   officegrid.setAutoExpandColumn("ccode");  
		  //  panel.setLayout(new BorderLayout());
		    
		    //----------------------------
		    final BaseFormPanel formpanel = new BaseFormPanel(branchorgadd);  
		    formpanel.setHeaderVisible(false);  
		  
		    TextField<String> branchtelephone = new TextField<String>();  
		    branchtelephone.setName("telephone");  
		    branchtelephone.setFieldLabel("办公电话"); 
		    
		    //-----------码名映射
		    ModelType combotype = new ModelType();  
		    combotype.setRoot("records") ;  
		    combotype.setRecordName("record");  
		    combotype.setTotalName("totle");
		    combotype.addField("code","ccode");  
		    combotype.addField("name","cname");  
		    StoreInfo  comboinfo= new StoreInfo();
		    
		    comboinfo.setTablename("ccode");
		    comboinfo.setSql("select * from ccode");
		     combo = new BaseComboBox(combotype,comboinfo);  

//		    BaseModel m = new BaseModel();
//		    BaseModel m2 = new BaseModel();
//		    BaseModel m3 = new BaseModel();
//		    BaseModel m4 = new BaseModel();
//		    BaseModel m5 = new BaseModel();
//		    BaseModel m6 = new BaseModel();
//		    BaseModel m7 = new BaseModel();
//		    BaseModel m8 = new BaseModel();
//		    BaseModel m9 = new BaseModel();
//		    m.set("name", "zgw1");
//		    m.set("value", "zgwvalue1");
//		    m2.set("name", "zgw2");
//		    m2.set("value", "zgwvalue2");
//		    m3.set("name", "zgw3");
//		    m3.set("value", "zgwvalue3");
//		    
//		    m4.set("name", "zgw4");
//		    m4.set("value", "zgwvalue4");
//		    m5.set("name", "zgw5");
//		    m5.set("value", "zgwvalue5");
//		    m6.set("name", "zgw6");
//		    m6.set("value", "zgwvalue6");
//		    m7.set("name", "zgw7");
//		    m7.set("value", "zgwvalue7");
//		    m8.set("name", "zgw8");
//		    m8.set("value", "zgwvalue8");
//		    m9.set("name", "zgw9");
//		    m9.set("value", "zgwvalue9");
//		    
//		    ListStore ls = new ListStore();
//		    ls.add(m);
//		    ls.add(m2);
//		    ls.add(m3);
//		    ls.add(m4);
//		    ls.add(m5);
//		    ls.add(m6);
//		    ls.add(m7);
//		    ls.add(m8);
//		    ls.add(m9);
//		    combo.setStore(ls);  
//		    combo.setTypeAhead(true);  
//		  
		    combo.setDisplayField("name");  
		    combo.setValueField("value");
		 //  combo.setRawValue("ddddd");
		  //  formpanel.add(branchtelephone);  
		    formpanel.add(combo);
		    
		    List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();
			ColumnConfig bcode = new ColumnConfig("bcode", "人员编码", 100);
			
			bocodecolumns.add(bcode);

			ColumnConfig bname = new ColumnConfig("bname", "人员名", 100);
			
			bocodecolumns.add(bname);
			
			ModelType bcodetype = new ModelType();
			bcodetype.setRoot("records") ;  
			bcodetype.setRecordName("record");  
			bcodetype.setTotalName("totle");
			bcodetype.addField("bcode");
			bcodetype.addField("bname");

			StoreInfo bcodeinfo = new StoreInfo();
			bcodeinfo.setTablename("bcode");
			bcodeinfo.setSql("select bcode,bname from bcode");
		    BaseGridEditor mm = new BaseGridEditor(bocodecolumns,bcodetype,bcodeinfo,"bname");
		    mm.setName("mobil");
		    mm.setFieldLabel("zzz");
		    
		    formpanel.add(mm);
		    final TextField<String> mobil = new TextField<String>();  
		    mobil.setName("mobil");  
		    mobil.setFieldLabel("移动电话");  
		    
		    formpanel.add(mobil);  
		  
		    final TextField<String>  privatemobil = new TextField<String> ();  
		    privatemobil.setName("privatemobil");  
		    privatemobil.setFieldLabel("私人电话");  
		    formpanel.add(privatemobil);  
		  
		    privatemobil.addKeyListener(new KeyListener(){
		    	  public void componentKeyUp(ComponentEvent event) {
		    		  mobil.setValue(privatemobil.getValue());
		    	  }
		    });
		    
		    
		    TextField<String>  fax = new TextField<String> ();  
		    fax.setName("fax");  
		    fax.setFieldLabel("传真");  
		   
		    formpanel.add(fax);  
		    
		    TextField<String>  addrtype = new TextField<String> ();  
		    addrtype.setName("addrtype");  
		    addrtype.setFieldLabel("地址类型");  
		   
		    formpanel.add(addrtype);  
		    
		   final TextField<String>  postcode = new TextField<String> ();  
		    postcode.setName("postcode");  
		    postcode.setFieldLabel("邮编");  
		    
		    formpanel.add(postcode);  
		    
		    TextField<String>  addr = new TextField<String> ();  
		    addr.setName("addr");  
		    addr.setFieldLabel("通讯地址");  
		   
		    formpanel.add(addr); 
		    ToolBar tb = new ToolBar();
		    Button button = new Button("拷贝");
		    Button button2 = new Button("拷贝2");
		    button.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					// TODO Auto-generated method stub
//					BaseStore<BaseModelData> bb = new BaseStore<BaseModelData>();
//					BaseModelData bmd = new BaseModelData();
//					bmd.set("addr","庄光旺的地址");
//					bmd.set("postcode","庄光旺的邮编");
//					bb.add(bmd);
//					formpanel.getBasestore().setValue(1, "addr", "庄光旺的地址");
//					formpanel.getBasestore().setValue(1, "postcode", "庄光旺的邮编");
					//postcode.setValue("庄光旺的邮编1");
//					MessageBox.alert("",""+ formpanel.getBasestore().getValue(1, "postcode"), null);
				//	formpanel.el().mask("dd");
					SendServlet sendservlet = new SendServlet();
					try {
						sendservlet.sendServlet("BaseServlet", "Action=test", new RequestCallback(){

							@Override
							public void onError(Request request, Throwable exception) {
								// TODO Auto-generated method stub
								
							}

							@Override
							public void onResponseReceived(Request request,
									Response response) {
								// TODO Auto-generated method stub
								System.out.println(response.getText());
							//	formpanel.getBasestore().setValue(1, "postcode", response.getText());
								  Document doc = XMLParser.parse(response.getText());
								  NodeList list = doc.getElementsByTagName("record");
								  ArrayList<ModelData> records = new ArrayList<ModelData>();
								  
								  for (int i = 0; i < list.getLength(); i++) {
									  Node node = list.item(i);
								      Element elem = (Element) node;
								 //     DomQuery.selectValue("add", getJsObject(elem));
								     for(int j=0; j<elem.getChildNodes().getLength();j++)
								     {
								    	 
								    	 String name =  elem.getChildNodes().item(j).getNodeName();
								    	 formpanel.getBasestore().setValue( name, XML.getValue(elem,name));
								     }
								  }
							}
							
						});
					} catch (RequestException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				//	formpanel.getFormbinding().bind(formpanel.getBasestore().getAt(1));
					formpanel.recalculate();
					formpanel.repaint();
				}});
			final java.util.LinkedList<BaseStore> ll = new java.util.LinkedList<BaseStore>();
			ll.add(formpanel.getBasestore());
			ll.add(officestore);
		    button2.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					// TODO Auto-generated method stub
					
				
					BaseCopyUI bcu = new BaseCopyUI(ll,"","1001");
					try {
						bcu.initUI();
					} catch (RequestException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					//bcu.sendServlet();
				}
		    	
		    	
		    });
		    RadioGroup myRg = new RadioGroup();
		    Radio bananas = new Radio();
		    bananas.setBoxLabel("Bananas");
		    Radio apples = new Radio();
		    apples.setBoxLabel("Apples");
		    myRg.setFieldLabel("Fruits");
		    myRg.add(bananas);
		    myRg.add(apples);
		    tb.add(button);
		    tb.add(button2);
		    tb.add(myRg);
		    formpanel.setTopComponent(tb);
		    formpanel.setScrollMode(Scroll.AUTO);
		    formpanel.inited();
//		    FormBinding formBindings = new FormBinding(formpanel, true);  
//		    formBindings.setStore(branchorgadd); 
		
//		    
//		    FormImage lf = new FormImage();
//		    lf.setName("imageurl");
//		    lf.setFieldLabel("zzdd");
//		   
//		    formpanel.add(lf);  
		    
		    //-------------------------------
		    
		
		    
		    //----------------家庭成员ccodecustomersolicitude
		    
		    
			 List<ColumnConfig> customercolumns = new ArrayList<ColumnConfig>();  
			 
	
			  
			    ColumnConfig leaguertype = new ColumnConfig("leaguertype", "家庭成员", 100); 
			    TextField<String> leaguertext = new TextField<String>(); 
			    lname.setEditor(new CellEditor(leaguertext));
			    customercolumns.add(leaguertype);
			    ColumnConfig leaguername = new ColumnConfig("leaguername", "姓名", 100); 
			    TextField<String> leaguernametext = new TextField<String>(); 
			    dept.setEditor(new CellEditor(leaguernametext));
			    customercolumns.add(leaguername);
		
			   
			    ColumnModel customercm = new ColumnModel(customercolumns);  
			    
			 
			 
			 ModelType customertype = new ModelType();  
			 customertype.setRoot("records");  
			 customertype.setRecordName("record");  
	
			 customertype.addField("ccode", "ccode");  
			 customertype.addField("leaguertype");  
			 customertype.addField("leaguertype");  
			
			     
			    StoreInfo customerinfo= new StoreInfo();
			    
			    customerinfo.setTablename("ccodelinkman_info");
			    customerinfo.setSql("select * from ccodelinkman_info");
			    customerinfo.setParent(store);
			    customerinfo.setLinkparentcolumns(new String[]{"ccode"});
			    customerinfo.setKeyname(new String[]{"ccode"});
				
			    customertypestore = new BaseStore<JDBCModelData>(customertype,customerinfo);
			   customertypestore.setName("ccodelinkman_info");
			    BaseGrid customertypegrid=new BaseGrid(customertypestore, customercm);
		    
		    //---------------------
		    //--
			    FormPanel formcustomerpanel = new FormPanel();  
			    formcustomerpanel.setHeaderVisible(false);  
			  
			    TextField<String> birthdayc = new TextField<String>();  
			    birthdayc.setName("birthday");  
			    birthdayc.setFieldLabel("生日"); 
			    
			    formcustomerpanel.add(birthdayc);  
			  
			    TextField<String> commemorateday = new TextField<String>();  
			    commemorateday.setName("commemorateday");  
			    commemorateday.setFieldLabel("纪念日");  
			    
			    formcustomerpanel.add(commemorateday);  
			  
			    TextField religion = new TextField();  
			    religion.setName("religion");  
			    religion.setFieldLabel("信仰");  
			    formcustomerpanel.add(religion);  
			  
			    TextField bekeenon = new TextField();  
			    bekeenon.setName("bekeenon");  
			    bekeenon.setFieldLabel("主要爱好");  
			   
			    formcustomerpanel.add(bekeenon);  
			    
			    TextField tourexperience = new TextField();  
			    tourexperience.setName("tourexperience");  
			    tourexperience.setFieldLabel("旅游经历");  
			   
			    formcustomerpanel.add(tourexperience);  
			    
			    TextField workexperience = new TextField();  
			    workexperience.setName("workexperience");  
			    workexperience.setFieldLabel("工作经历");  
			    
			    formcustomerpanel.add(workexperience);  
			    
			    TextField occupation = new TextField();  
			    occupation.setName("occupation");  
			    occupation.setFieldLabel("职业");  
			   
			    formcustomerpanel.add(occupation);  
			    
			    TextField workheadship = new TextField();  
			    workheadship.setName("workheadship");  
			    workheadship.setFieldLabel("工作职位");  
			   
			    formcustomerpanel.add(workheadship);  
			    
			    TextField remark = new TextField();  
			    remark.setName("remark");  
			    remark.setFieldLabel("备注");  
			   
			    formcustomerpanel.add(remark);  
			    
			    FormBinding formcustomerBindings = new FormBinding(formcustomerpanel, true);  
			    formcustomerBindings.setStore(customertypestore); 
			    
			   
			    //--end
		
		    
		    ContentPanel panel = new ContentPanel();
		    panel.setHeaderVisible(false);
		    panel.setLayout(new  TableLayout(4));
		    

		    TableData td1= new TableData();
		    td1.setColspan(2);
		    

		   
		    TableData td2= new TableData();

		    td2.setColspan(2);
			   
		    TableData td3= new TableData();

		    td3.setColspan(2);
			   
		    TableData td4= new TableData();

		    td4.setColspan(2);
		    branchorgaddgrid.setSize(400, 200);
		    formpanel.setSize(400, 200);
		    panel.add(branchorgaddgrid,td1);
		    panel.add(formpanel,td2);
		    customertypegrid.setSize(400, 200);
		    formcustomerpanel.setSize(400, 200);
		    panel.add(customertypegrid,td3);      
		    panel.add(formcustomerpanel,td4);
		  
		    panel.setScrollMode(Scroll.AUTO);
		    panel.setSize(800,500);
		 return panel;
	 }
	 public ContentPanel createCodeLinkPanel() {  
		 ContentPanel panel = new ContentPanel();  
		 List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		 
		    ColumnConfig column = new ColumnConfig("ccode", "ccode", 100); 
		    TextField<String> text = new TextField<String>(); 
		    column.setEditor(new CellEditor(text));
		    columns.add(column);
		    ColumnConfig gname = new ColumnConfig("name", "cname", 100); 
		    TextField<String> gnametext = new TextField<String>(); 
		    gname.setEditor(new CellEditor(gnametext));
		    columns.add(gname);
	
		    columns.add(new ColumnConfig("moble", "moble", 100));  
		    ColumnModel cm = new ColumnModel(columns);  
		    
		    //--set modetype 
		    ModelType type = new ModelType();  
		    type.setRoot("records");  
		    type.setRecordName("record");  
		    type.addField("ccode", "ccode");  
		    type.addField("name");  
		    type.addField("moble");  
		    type.addField("imagepath");  
		    StoreInfo info= new StoreInfo();
		    info.setTablename("codelinker");
		    info.setSql("select * from codelinker");
		    info.setParent(store);
		    info.setLinkparentcolumns(new String[]{"ccode"});
		   codelinkstore = new BaseStore<JDBCModelData>(type,info);
		   codelinkstore.setName("parent");
		   
		 
//		   
//		   codelinkstore.setParent(store);
//		   codelinkstore.setLinkparentcolumns(new String[]{"ccode"});
		   
		   //-------------------------
//		   ListView<BeanModel> view = new ListView<BeanModel>() {  
//			      @Override  
//			      protected BeanModel prepareData(BeanModel model) {  
//			        String s = model.get("imagepath");  
//			        model.set("shortName", Util.ellipse(s, 15));  
//			        return model;  
//			      }  
//			  
//			    };  
			     view = new ListView();
			   // view.setPosition(10, 10);
			  //  view.setAutoHeight(true);
			
			  //  view.setWidth(200);
			    view.setAutoHeight(true);  
			    view.setTemplate(getTemplate());  
			   view.setStore(codelinkstore);  
			    view.setItemSelector("div.thumb-wrap");  
			   
			    
			  //  panel.setLayout(new FitLayout());  
			    panel.setWidth(500);  
			   panel.add(view);  
	/*	    grid2=new BaseGrid(codelinkstore, cm);
		    grid2.setAutoExpandColumn("ccode");  
//		    grid2.setLinkparent(grid);
//		    grid2.setLinkparentcolumns(new String[]{"ccode"});
		    
		 //   panel.setLayout(new BorderLayout());
	//	panel.setLayout(new RowLayout(Orientation.VERTICAL));
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(0));
		// centerData.setSplit(true);

	//	panel.add(grid2, centerData);

		// panel.add(grid2, new RowData(1, 1));
		panel.setScrollMode(Scroll.ALWAYS);
		 panel.add(grid2);
		 panel.setHeaderVisible(false);
		*/
			   
			//    panel.add(grid2);
		return panel;
		 
	 }
	 
	 public ContentPanel uploadpanel()
	 {
		 ContentPanel panel = new ContentPanel();  
		 final com.google.gwt.user.client.ui.FormPanel form = new com.google.gwt.user.client.ui.FormPanel();
		 form.setEncoding(com.google.gwt.user.client.ui.FormPanel.ENCODING_MULTIPART);
		 form.setMethod(com.google.gwt.user.client.ui.FormPanel.METHOD_POST);
		 form.addStyleName("table-center");
		 form.addStyleName("demo-panel-padded");
		 form.setWidth("275px");
		 

		 VerticalPanel holder = new VerticalPanel();

		 FileUpload upload = new FileUpload();
		
		// com.google.gwt.user.client.
		
		 
		// com.extjs.gxt.ui.client.widget.form.FileUploadField ff = new com.extjs.gxt.ui.client.widget.form.FileUploadField();
		
		// ff.setRegex(regex)
		 upload.setName("upload");
		 holder.add(upload);

		 holder.add(new HTML("<hr />"));
		 
		 holder.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT);
		 holder.add(new com.google.gwt.user.client.ui.Button("Submit", new ClickListener()
		 {
		 	public void onClick(Widget sender)
		 	{
		 		 form.submit();
		 	}
		 }));

		 form.add(holder);

		  form.setAction("/"+GWT.getModuleName()+"/BaseFileUploadServlet");

		 form.addFormHandler(new FormHandler()
		 {
		 	public void onSubmit(FormSubmitEvent event)
		 	{
		 		System.out.println("err in upload!"+event.toString());
//		 		 if (something_is_wrong)
//		 		 {
//		 		 Take some action
//		 		 event.setCancelled(true);
//		 		 }
		 	}

		 	public void onSubmitComplete(FormSubmitCompleteEvent event)
		 	{
		 		Window.alert(event.getResults());
		 	}
		 });
		 panel.add(form);
		 return panel;
	 }
	 public static native void it(String html) /*-{
	 	$wnd.alert(html);
	}-*/;
	 public native static void test(String html)/*-{
		$wnd.alert(html);
	 }-*/;
	 private native String getTemplate() /*-{ 
    var o =  ['<ul style="list-style:none;width:500px"> ','<tpl for=".">', 
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white" >', 
    '<div class="thumb" ><img  style="float:left;display:block;overflow:hidden;width:120px;height:120px;border:3px double #eee;margin: 0 2px 2px 0" src="http://www.google.cn/intl/zh-CN/images/logos/translate_logo.gif" title="{name}"></div>', 
    '<span class="x-editable">{shortName}</span></div>', 
    '</tpl>', '</ul>',
    '<div class="x-clear"></div>'].join(""); 
  
  var z = ['<ul style="list-style:none;width:500px"> ','<tpl for=".">',
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white" >',
   
  '<div class="thumb" ><li style="float:left;display:block;overflow:hidden;width:120px;height:120px;border:3px double #eee;margin: 0 2px 2px 0"><img src="http://www.google.cn/intl/zh-CN/images/logos/translate_logo.gif" alt="" /></li></div>' ,

  '<span class="x-editable">{shortName}</span></div>',
  '</tpl>',
  '</ul> ' ,'<div class="x-clear"></div>'].join("");

    var w= ['<ul style="list-style:none"> ','<tpl  for=".">', 
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white">', 
    '<div class="thumb" ><li style="float:left;display:block;overflow:hidden;width:60px;height:60px;border:3px double #eee;margin: 0 2px 2px 0"><img src="http://www.google.cn/intl/zh-CN/images/logos/translate_logo.gif" title="{name}"></li></div>', 
    '<span class="x-editable">{shortName}</span></div>', 
    '</tpl>', '</ul> ' ,
    '<div class="x-clear"></div>'].join(""); 
        var r= ['<tpl  for=".">', 
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white;float:left;">', 
    '<div class="thumb" style="float:left" ><img style="width:100px;height:100px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{imagepath}" title="{name}"></div>', 
    '<span class="x-editable">{shortName}</span></div>', 
    '</tpl>',
    '<div class="x-clear"></div>'].join(""); 
    return r;
	//     return '<img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" title="{name}"><img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" title="{name}">';
	    }-*/;  
	 
	
}
